import {
    Component, ComponentFactoryResolver, ElementRef, ViewContainerRef, Renderer2, OnInit
} from '@angular/core';
import { DrawService } from '../../../common/draw/draw.service';
import { PsMachineDetailComponent } from '../../../detail/psMachine/psMachine.detail.component';
import { EsCommonService } from '../../../common/escommon.service';
import { CloudMachineService } from '../../../common/cloudMachine.service';
import { setInterval } from 'core-js/library/web/timers';
import { Router } from '@angular/router';

@Component({
    templateUrl: './order.component.html',
    styleUrls: ['./order.component.css', '../../../app.component.css'],
})
export class OrderComponent implements OnInit {
    basic = false;
    cpu: Array<any> = [
        {
            name: '单核'
        },
        {
            name: '双核'
        },
        {
            name: '4核'
        },
        {
            name: '8核'
        },
        {
            name: '16核'
        },
        {
            name: '32核'
        },
        {
            name: '48核'
        }
    ];
    memory: Array<any> = [
        {
            name: '1GB'
        },
        {
            name: '2GB'
        },
        {
            name: '4GB'
        },
        {
            name: '8GB'
        }
    ];
    os: Array<any> = [
        {
            name: 'CentOS 7.2',
            disk: '20GB'
        },
        {
            name: 'windows 2008',
            disk: '30GB'
        },
        {
            name: 'windows 2008R2',
            disk: '30GB'
        },
        {
            name: 'IBM AIX',
            disk: '25GB'
        },
        {
            name: 'Red Hat Linux 9',
            disk: '25GB'
        }
    ];
    file = [];
    netWork = [1, 2, 4, 8, 10, 20, 50, 100];
    selectCpu: any;
    selectMemory: any;
    selectOs;
    selectFile;
    selectNetWork;
    userName;
    password;
    rePassword;
    comment;
    modalInfo;
    constructor(private elementref: ElementRef,
        private renderer: Renderer2, private esCommonService: EsCommonService, private router: Router,
        private viewContainerRef: ViewContainerRef, private resolver: ComponentFactoryResolver) {
    }

    ngOnInit(): void {
        this.selectCpu = this.cpu[0];
        this.selectMemory = this.memory[0];
        this.selectOs = this.os[0];
        this.selectOs.selectName = this.selectOs.name;
        for (let i = 40; i <= 100; i = i + 5) {
            this.file.push(i + "GB");
        }

        this.selectFile = this.file[0];
        this.selectNetWork = this.netWork[0];
        this.userName = 'root';
    }

    select(type, obj?) {
        switch (type) {
            case 'cpu':
                this.selectCpu = obj;
                break;
            case 'memory':
                this.selectMemory = obj;
                break;
            case 'os':
                for (let o of this.os) {
                    if (o.name == this.selectOs.selectName) {
                        this.selectOs = o;
                        this.selectOs.selectName = o.name;
                    }
                }

                break;
        }
    }

    submit() {
        if (this.password && this.rePassword) {
            if (this.password === this.rePassword) {
                this.modalInfo = "提交订单成功!";
            } else {
                this.modalInfo = "请确认两次密码输入一致";
            }
        } else {
            this.modalInfo = "请确认两次密码输入有效";
        }
        this.basic = true;
    }
}